﻿using CRM.Infrastructure.Attr;
using CRM.Infrastructure.Dto.Request.Customer;
using CRM.Infrastructure.Dto.Response;
using CRM.Infrastructure.EFCore.Mysql;
using Crm.Infrastructure.IOC;
using Crm.Service.Instance;
using CRM.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Infrastructure.IOC;
using CRM.Infrastructure.Tools;
using CRM.Infrastructure.Dto.Response.Customer;
using Microsoft.EntityFrameworkCore;
using CRM.Infrastructure.Dto.Response.Dictionary;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Security.Cryptography;
using CRM.Infrastructure.Dto.Response.Vip;

namespace CRM.Service.Instance
{
    [Inject_]
    public class Customer_Service : Base_Service, I_Customer_Service
    {
        private readonly Customer_IOC _customer_IOC;
        private readonly Dictionary_IOC _dictionary_IOC;
        private readonly Login_IOC _login_IOC;

        public Customer_Service(Customer_IOC customer_IOC, Dictionary_IOC dictionary_IOC, Login_IOC login_IOC)
        {
            _customer_IOC = customer_IOC;
            _dictionary_IOC = dictionary_IOC;
            _login_IOC=login_IOC;



        }
        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<Api_Response_Dto> Add_Customer(Customer_Request_Dto dto)
        {


            Customer customer = new Customer()
            {
                CId = Config.GUID_2(),
                CAddress = dto.address,
                CAuthor = dto.author,
                CCreateTime = DateTime.Now,
                CDesc = null,
                CFollowTime = DateTime.Parse(dto.follow_time),
                CLevel = dto.level,
                CName = dto.name,
                CNextTime = DateTime.Now,
                CPhone = dto.phone,
                CQq = dto.qq,
                CRecord = dto.author,
                CRemark = dto.remark,
                CResponsibility = dto.responsibility,
                CSchool = dto.school,
                CSeasTime = DateTime.Now.AddDays(30),
                CSource = dto.source,
                CStatus = 1,
                CType = dto.type,
                CUpdateTime = null,
                CWechat = dto.wechat,
                CsuccessPercent =0
            };
            _customer_IOC._customer_EFCore.Add(customer);
            var result = await _customer_IOC._customer_EFCore.SaveChangesAsync();
            return Result(result);
        }

        /// <summary>
        /// 新增客户跟进记录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<Api_Response_Dto> Add_Record(Record_Request_Dto dto)
        {
            var count = await _customer_IOC._customer_record_EFCore.QueryAll(d => d.CrCId == dto.customer).CountAsync();
            
            CustomerRecord customerRecord = new CustomerRecord()
            {
                CrId = Config.GUID_2(),
                CrContent = dto.content,
                CrLocation = dto.location,
                CrCId = dto.customer,
                CrCreateTime = DateTime.Now,
                CrDate = DateTime.Parse(dto.date!),
                CrDesc = null,
                CrIsConvert = dto.isConvert,
                CrNextTime = string.IsNullOrEmpty(dto.next_time) ? null : DateTime.Parse(dto.next_time),
                CrNo = count + 1,
                CrResult = dto.result,
                CrSuccess = dto.success,
                CrAuthor = dto.author,
            };
            _customer_IOC._customer_record_EFCore.Add(customerRecord);

            var customer = await _customer_IOC._customer_EFCore.QueryAll(d => d.CId == customerRecord.CrCId).SingleAsync();
            customer.CsuccessPercent = customerRecord.CrSuccess;
            _customer_IOC._customer_EFCore.Update(customer);
            var result = _customer_IOC._customer_record_EFCore.Transactions(_customer_IOC._customer_EFCore);

            if (dto.isConvert == 1)
            {
                Customervip customervip = new Customervip()
                {
                    CvId = Config.GUID_2(),
                    CvName = customer.CName,
                    CvPhone = customer.CPhone,
                    CvWechat = customer.CWechat,
                    CvQq = customer.CQq,
                    CvAddress = customer.CAddress,
                    CvRechargeAmount = 0,
                    CvConsumptionGiftAmount = 0,
                    CvConsumptionAmount = 0,
                    CvTransactionCount = 0,
                    CvCustomerId= customer.CId,
                    CvResponsible = customer.CResponsibility,
                    CvCreationTime= DateTime.Now,
                    CvLevel= "8f2eabd9ecf811ef9301902e1656e0d2"
                };
                _customer_IOC._customer_vip_EFCore.Add(customervip);
                _customer_IOC._customer_vip_EFCore.SaveChanges();

                var iq = _customer_IOC._customer_EFCore.QueryAll(d => d.CId == customer.CId).Single();
                iq.CStatus = 2;
                _customer_IOC._customer_EFCore.Update(iq);
                _customer_IOC._customer_EFCore.SaveChanges();
            }

           
            return Result(result ? 1 : 0);
        }

        /// <summary>
        /// 新增会员
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<Api_Response_Dto> Add_Vip(Vip_Request_Dto dto)
        {
            Customervip customerVip = new Customervip()
            {
                CvId = Config.GUID_2(),
                CvAddress = dto.address,
                CvCareer = dto.career,
                CvName = dto.name,
                CvPhone = dto.phone,
                CvQq = dto.qq,
                CvWechat = dto.wechat,
                CvResponsible = dto.responsible,
                CvCustomerId = dto.customer_id,
                CvCreateTime = DateTime.Now,
                CvConsumptionAmount = 0,
                CvConsumptionGiftAmount = 0,
                CvGiftAmount = 0,
                CvRechargeAmount = 0,
                CvDesc = null,
                CvLastTime = null,
                CvTransactionCount = 0,
            };
            _customer_IOC._customer_vip_EFCore.Add(customerVip);

            if (dto.customer_id != null)
            {
                var customer = await _customer_IOC._customer_EFCore.QueryAll(d => d.CId == dto.customer_id).SingleOrDefaultAsync();
                if (customer != null)
                {
                    customer.CStatus = 2;//指定客户状态为已转换
                    _customer_IOC._customer_EFCore.Update(customer);

                    var count = await _customer_IOC._customer_record_EFCore.QueryAll(d => d.CrCId == customer.CId).CountAsync();

                    //新增一条跟进记录
                    CustomerRecord customerRecord = new CustomerRecord()
                    {
                        CrId = Config.GUID_2(),
                        CrContent = "客户转会员",
                        CrAuthor = dto.responsible,
                        CrCId = customer.CId,
                        CrCreateTime = DateTime.Now,
                        CrDate = DateTime.Now,
                        CrIsConvert = 1,
                        CrDesc = null,
                        CrLocation = "",
                        CrNextTime = DateTime.Now,
                        CrNo = count + 1,
                        CrResult = null,
                        CrSuccess = 100
                    };
                    _customer_IOC._customer_record_EFCore.Add(customerRecord);
                }
            }


            var result = _customer_IOC._customer_vip_EFCore.Transactions(_customer_IOC._customer_EFCore, _customer_IOC._customer_record_EFCore);
            return Result(result ? 1 : 0);
        }

        /// <summary>
        /// 获取客户列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<Api_Response_Dto> Get_Customers(int page, int limit, string key, string uid)
        {
            var now = DateTime.Now;
            var iq = _customer_IOC._customer_EFCore.QueryAll(out int total, page, limit,
                false, d => d.CCreateTime, d => (d.CName!.Contains(key)) && (d.CResponsibility == uid));
            var data = await iq.Select(d => new Customer_Response_Dto
            {
                id = d.CId,
                name = d.CName,
                address = d.CAddress,
                author = d.CAuthor,
                follow_time = d.CFollowTime!.Value.ToString("yyyy-MM-dd"),
                level = d.CLevel,
                next_time = d.CNextTime!.Value.ToString("yyyy-MM-dd"),
                phone = d.CPhone,
                qq = d.CQq,
                record = d.CRecord,
                remark = d.CRemark,
                Responsibility = d.CResponsibility,
                school = d.CSchool,
                seas_time = d.CSeasTime!.Value.ToString("yyyy-MM-dd"),
                source = d.CSource,
                status = d.CStatus,
                time = d.CCreateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                update_time = d.CUpdateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                wechat = d.CWechat,
                type = d.CType,
                success_percent = d.CsuccessPercent ?? 0,
                count=0,
                record_count = 0,
            }).ToListAsync();
            
            List<string> dList = new List<string>();
            dList.AddRange(data.Select(d => d.type!).ToList());
            dList.AddRange(data.Select(d => d.source!).ToList());
            dList.AddRange(data.Select(d => d.level!).ToList());

            var dics = await _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => dList.Contains(d.DId)).ToListAsync();

            var cids = data.Select(d => d.id).ToList();
            var count= await _customer_IOC._customer_record_EFCore.QueryAll(d=>data.Select(e=>e.id).Contains(d.CrCId)).ToListAsync();
            var record_count = await _customer_IOC._customer_vip_EFCore.QueryAll(d => data.Select(e => e.id).Contains(d.CvCustomerId)).ToListAsync();
            var record = 0;
            if (cids.Count == 0)
            {
                data.ForEach(d =>
                {
                    d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;
                    d.type = dics.Where(e => e.DId == d.type).SingleOrDefault()?.DName;
                    d.source = dics.Where(e => e.DId == d.source).SingleOrDefault()?.DName;
                    if (DateTime.Now >Convert.ToDateTime(d.seas_time))
                    {
                        var date = _customer_IOC._customer_EFCore.QueryAll(e => e.CId == d.id).Single();
                        date.CStatus = 0;
                        date.CResponsibility = null;
                        date.CNextTime = null;
                        _customer_IOC._customer_EFCore.Update(date);
                        _customer_IOC._customer_EFCore.SaveChanges();
                    }
                    if (d.status == 2)
                    {
                        d.success_percent = 100;
                    }
                });
                return Result(1, "ok", new
                {
                    data,
                    total
                });
            }
            else
            {
                //var records = await _customer_IOC._customer_record_EFCore.QueryAll(d => cids.Contains(d.CrCId)).ToListAsync();
                    data.ForEach(d =>
                    {
                        d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;
                        d.type = dics.Where(e => e.DId == d.type).SingleOrDefault()?.DName;
                        d.source = dics.Where(e => e.DId == d.source).SingleOrDefault()?.DName;
                        if (DateTime.Now > Convert.ToDateTime(d.seas_time))
                        {
                            var date = _customer_IOC._customer_EFCore.QueryAll(e => e.CId == d.id).Single();
                            date.CStatus = 0;
                            date.CResponsibility = null;
                            date.CNextTime = null;
                            _customer_IOC._customer_EFCore.Update(date);
                            _customer_IOC._customer_EFCore.SaveChanges();
                        }
                        foreach (var i in record_count)
                        {
                            if (i.CvCustomerId == d.id)
                            {
                                record += 1;
                            }

                        }
                        foreach (var i in count)
                        {
                            if (i.CrCId==d.id)
                            {
                                d.count+=1;
                            }
                                
                        }
                        //d.record_count = records.Where(e => e.CrCId == d.id).Count();
                        if (d.status == 2)
                        {
                            d.success_percent = 100;
                        }
                    });
                
                    return Result(1, "ok", new
                    {
                        data,
                        record,
                        total
                    });
                
            }
        
        }
        
            public async Task<Api_Response_Dto> Get_Customers_HighSeas(int page, int limit, string key)
        {
            var now = DateTime.Now;
            var iq = _customer_IOC._customer_EFCore.QueryAll(out int total, page, limit,
                false, d => d.CCreateTime, d => (d.CName!.Contains(key)));
            var data = await iq.Select(d => new Customer_Response_Dto
            {
                id = d.CId,
                name = d.CName,
                address = d.CAddress,
                author = d.CAuthor,
                follow_time = d.CFollowTime!.Value.ToString("yyyy-MM-dd"),
                level = d.CLevel,
                next_time = d.CNextTime!.Value.ToString("yyyy-MM-dd"),
                phone = d.CPhone,
                qq = d.CQq,
                record = d.CRecord,
                remark = d.CRemark,
                Responsibility = d.CResponsibility,
                school = d.CSchool,
                seas_time = d.CSeasTime!.Value.ToString("yyyy-MM-dd"),
                source = d.CSource,
                status = d.CStatus,
                time = d.CCreateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                update_time = d.CUpdateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                wechat = d.CWechat,
                type = d.CType,
                success_percent = d.CsuccessPercent ?? 0,
                count = 0,
                record_count = 0,
            }).ToListAsync();

            List<string> dList = new List<string>();
            dList.AddRange(data.Select(d => d.type!).ToList());
            dList.AddRange(data.Select(d => d.source!).ToList());
            dList.AddRange(data.Select(d => d.level!).ToList());

            var dics = await _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => dList.Contains(d.DId)).ToListAsync();

            var cids = data.Select(d => d.id).ToList();
            var count = await _customer_IOC._customer_record_EFCore.QueryAll(d => data.Select(e => e.id).Contains(d.CrCId)).ToListAsync();
            var record_count = await _customer_IOC._customer_vip_EFCore.QueryAll(d => data.Select(e => e.id).Contains(d.CvCustomerId)).ToListAsync();
            var record = 0;
            if (cids.Count == 0)
            {
                data.ForEach(d =>
                {
                    d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;
                    d.type = dics.Where(e => e.DId == d.type).SingleOrDefault()?.DName;
                    d.source = dics.Where(e => e.DId == d.source).SingleOrDefault()?.DName;
                    if (DateTime.Now > Convert.ToDateTime(d.seas_time))
                    {
                        var date = _customer_IOC._customer_EFCore.QueryAll(e => e.CId == d.id).Single();
                        date.CStatus = 0;
                        date.CResponsibility = null;
                        date.CNextTime = null;
                        _customer_IOC._customer_EFCore.Update(date);
                        _customer_IOC._customer_EFCore.SaveChanges();
                    }
                    if (d.status == 2)
                    {
                        d.success_percent = 100;
                    }
                });
                return Result(1, "ok", new
                {
                    data,
                    total
                }); ;
            }
            else
            {
                //var records = await _customer_IOC._customer_record_EFCore.QueryAll(d => cids.Contains(d.CrCId)).ToListAsync();
                data.ForEach(d =>
                {
                    d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;
                    d.type = dics.Where(e => e.DId == d.type).SingleOrDefault()?.DName;
                    d.source = dics.Where(e => e.DId == d.source).SingleOrDefault()?.DName;
                    if (DateTime.Now > Convert.ToDateTime(d.seas_time))
                    {
                        var date = _customer_IOC._customer_EFCore.QueryAll(e => e.CId == d.id).Single();
                        date.CStatus = 0;
                        date.CResponsibility = null;
                        date.CNextTime = null;
                        _customer_IOC._customer_EFCore.Update(date);
                        _customer_IOC._customer_EFCore.SaveChanges();
                    }
                    foreach (var i in record_count)
                    {
                        if (i.CvCustomerId == d.id)
                        {
                            record += 1;
                        }

                    }
                    foreach (var i in count)
                    {
                        if (i.CrCId == d.id)
                        {
                            d.count += 1;
                        }

                    }
                    //d.record_count = records.Where(e => e.CrCId == d.id).Count();
                    if (d.status == 2)
                    {
                        d.success_percent = 100;
                    }
                });

                return Result(1, "ok", new
                {
                    data,
                    record,
                    total
                });

            }

        }

        /// <summary>
        /// 获取单个客户跟进记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Api_Response_Dto> Get_Single_Customer_Records(string id)
        {

            var iq = _customer_IOC._customer_EFCore.QueryAll(d => d.CId == id);
            if (!await iq.AnyAsync())
            {
                return Result(0, "参数错误");
            }

            var data = await _customer_IOC._customer_record_EFCore.QueryAll(d => d.CrCId == id).
                Select(d => new Record_Response_Dto
                {
                    id = d.CrCId,
                    content = d.CrContent,
                    name = $"第 {d.CrNo} 次跟进",
                    author = d.CrAuthor,
                    date = d.CrDate!.Value.ToString("yyyy-MM-dd"),
                    isConvert = d.CrIsConvert,
                    location = d.CrLocation,
                    next_time = d.CrNextTime!.Value.ToString("yyyy-MM-dd"),
                    no = d.CrNo,
                    result = d.CrResult,
                    success = d.CrSuccess,
                    time = d.CrCreateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss")
                }).ToListAsync();

            var dids = data.Select(d => d.result).ToList();
            var dics = await _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => dids.Contains(d.DId)).ToListAsync();
            data.ForEach(d =>
            {
                if (d.isConvert == 1)
                {
                    d.result = "已转化";
                }
                else
                {
                    d.result = dics.Where(e => e.DId == d.result).SingleOrDefault()?.DName;
                }
            });

            var customer = await iq.SingleAsync();

            data.Insert(0, new Record_Response_Dto
            {
                id = Config.GUID_2(),
                no = 0,
                content = "首次添加客户",
                name = "添加客户",
                success = customer.CsuccessPercent,
                location = "-",
                date = customer.CCreateTime!.Value.ToString("yyyy-MM-dd"),
                isConvert = 0,
                result = "待定",
                next_time = customer.CNextTime!.Value.ToString("yyyy-MM-dd"),
                time = customer.CCreateTime!.Value.ToString("yyyy-MM-dd")
            });


            return Result(1, "ok", data.OrderBy(d => d.no).ToList());

        }
        public async Task<Api_Response_Dto> Get_Level()
        {
            var now = DateTime.Now;
            var iq = _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => d.DDtId == "6e78ff75ecf811ef9301902e1656e0d2");
            var data = await iq.Select(d => new Dictionary_Type_Response_Dto
            {
                id=d.DId,
                name=d.DName,
                
            }).ToListAsync();


            return Result(1, "ok", new
            {
                data
            }); ;
        }
        public async Task<Api_Response_Dto> Get_Origin()
        {
            var now = DateTime.Now;
            var iq = _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => d.DDtId == "040207030147001aa0cd89595e5ed644");
            var data = await iq.Select(d => new Dictionary_Type_Response_Dto
            {
                id = d.DId,
                name = d.DName,

            }).ToListAsync();


            return Result(1, "ok", new
            {
                data
            }); ;
        }
        public async Task<Api_Response_Dto> Get_Type()
        {
            var now = DateTime.Now;
            var iq = _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => d.DDtId == "040207030147001aa0cd89595e5ed6u0");
            var data = await iq.Select(d => new Dictionary_Type_Response_Dto
            {
                id = d.DId,
                name = d.DName,

            }).ToListAsync();


            return Result(1, "ok", new
            {
                data
            });
        }
        public async Task<Api_Response_Dto> Get_user()
        {
            var iq = _login_IOC._sys_User_EFCore.QueryAll();
            var data = await iq.Select(d => new Dictionary_Type_Response_Dto
            {
                id = d.UId,
                name = d.UName,

            }).ToListAsync();


            return Result(1, "ok", new
            {
                data
            });
        }

        public async Task<Api_Response_Dto> Get_Customer_Details(string id)
        {
            var now = DateTime.Now;
            var iq = _customer_IOC._customer_EFCore.QueryAll(d=>d.CId==id);
            var data = await iq.Select(d => new Customer_Response_Dto
            {
                id = d.CId,
                name = d.CName,
                address = d.CAddress,
                author = d.CAuthor,
                follow_time = d.CFollowTime!.Value.ToString("yyyy-MM-dd"),
                level = d.CLevel,
                next_time = d.CNextTime!.Value.ToString("yyyy-MM-dd"),
                phone = d.CPhone,
                qq = d.CQq,
                record = d.CRecord,
                remark = d.CRemark,
                Responsibility = d.CResponsibility,
                school = d.CSchool,
                seas_time = d.CSeasTime!.Value.ToString("yyyy-MM-dd"),
                source = d.CSource,
                status = d.CStatus,
                time = d.CCreateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                update_time = d.CUpdateTime!.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                wechat = d.CWechat,
                type = d.CType,
                success_percent = d.CsuccessPercent ?? 0,
                count = 0,
                explain=d.CDesc
            }).ToListAsync();

            List<string> dList = new List<string>();
            dList.AddRange(data.Select(d => d.type!).ToList());
            dList.AddRange(data.Select(d => d.source!).ToList());
            dList.AddRange(data.Select(d => d.level!).ToList());

            var dics = await _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => dList.Contains(d.DId)).ToListAsync();

            var cids = data.Select(d => d.id).ToList();
            var count = await _customer_IOC._customer_record_EFCore.QueryAll(d => data.Select(e => e.id).Contains(d.CrCId)).ToListAsync();
            if (cids.Count == 0)
            {
                data.ForEach(d =>
                {
                    d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;
    
                    foreach (var i in count)
                    {
                        d.count++;
                    }
                    if (d.status == 2)
                    {
                        d.success_percent = 100;
                    }
                });
                return Result(1, "ok", new
                {
                    data,
                }); ;
            }
            else
            {
                //var records = await _customer_IOC._customer_record_EFCore.QueryAll(d => cids.Contains(d.CrCId)).ToListAsync();
                data.ForEach(d =>
                {
                    d.level = dics.Where(e => e.DId == d.level).SingleOrDefault()?.DName;

                    foreach (var i in count)
                    {
                        d.count++;
                    }
                    //d.record_count = records.Where(e => e.CrCId == d.id).Count();
                    if (d.status == 2)
                    {
                        d.success_percent = 100;
                    }
                });
                return Result(1, "ok", new
                {
                    data,
                });

            }
            
        }
        public async Task<Api_Response_Dto> Update_Customer_Details(Customer_Response_Dto dto)
        {
            var iq = _customer_IOC._customer_EFCore.QueryAll(d => d.CId == dto.id).Single();
            var iq2 = _dictionary_IOC._sys_Dictionary_EFCore.QueryAll(d => d.DDtId == "040207030147001aa0cd89595e5ed6u0");
            iq.CName = dto.name;
            iq.CType = dto.type;
            iq.CAddress = dto.address;
            iq.CSource = dto.source;
            iq.CPhone=dto.phone;
            iq.CDesc = dto.explain;
            iq.CNextTime = Convert.ToDateTime(dto.next_time);
            iq.CSeasTime= Convert.ToDateTime(dto.seas_time);
            _customer_IOC._customer_EFCore.Update(iq);
            var result = await _customer_IOC._customer_EFCore.SaveChangesAsync();
            return Result(result);
        }
        public async Task<Api_Response_Dto> Update_Customer(string id,string uid)
        {
            var iq = _customer_IOC._customer_EFCore.QueryAll(d => d.CId ==id).Single();
            iq.CResponsibility = uid;
            iq.CNextTime = DateTime.Now;
            iq.CSeasTime= DateTime.Now.AddDays(7);
            iq.CStatus = 1;
            _customer_IOC._customer_EFCore.Update(iq);
            var iq2 = _customer_IOC._customer_record_EFCore.QueryAll(d => d.CrCId == iq.CId);
            _customer_IOC._customer_record_EFCore.DeleteRange(iq2);
            var result = await _customer_IOC._customer_EFCore.SaveChangesAsync();
            var result2 = await _customer_IOC._customer_record_EFCore.SaveChangesAsync();
            return Result(result);
        }
        
    }
}
